/**
 * \class CNary
 * \brief This is a class to configure a N-ary toplogy which is one of DHT toplogies.
 * \version 0.3.2
 *
 * \author Woo-Hyun Kim (woorung@nhncorp.com, woorung@gmail.com)
 * \author http://blog.naver.com/wisereign .
 *
 * \date 2007/10/9
 */
#ifndef CNaryH
#define CNaryH
//-----------------------------------------------------------------
#include <iostream>
#include <vector>
#include <map>
#include <iterator>

#include "CDHT.h"
#include "CChord.h"

using namespace std;

class CNary : public CDHT
{
private:
	CChord *chord;

	map<int,string> local_skeys;

protected:
	void init();
	void fin();

	int local_spaces(char *ip);

	// in order to rearrange in latticed order
        static bool compare_by_smaller(const CServiceInfo &first, const CServiceInfo &second);

public:
        CNary();
        CNary(char *host, int port);
        virtual ~CNary();

	int bind(char *host, int port);

	// different from DHT's configure(char*)
	int configure(char *service_type);

	// used only in CNary
	int configure(char *service_type, char *space_type);

	// lookup in local spaces
	virtual vector<CServiceInfo> &llookup(char *ip, vector<CServiceInfo> &ls);

	// lookup all in workspaces
	virtual vector<CServiceInfo> &lookup(vector<CServiceInfo> &ls);

	// lookup in distribued spaces
	virtual CServiceInfo &lookup(char *key);
	//virtual CServiceInfo &predecessor(char *key);
	//virtual CServiceInfo &successor(char *key);

	// provide hidden space topology associated with n-ary topology
	CDHT *co_topology();
};
//-----------------------------------------------------------------
#endif
